using System;
using System.Collections.Generic;
using UnityEngine;

public class CurrencyPurchaseLayer : UILayer
{
	[Serializable]
	public class TabToCurrency
	{
		public UITabButton button;

		public CurrencyType currencyType;
	}

	public UITabController tabController;

	public List<TabToCurrency> currencyTabs = new List<TabToCurrency>();

	public UIAnimationElement animation;

	private Action<bool> onComplete;

	public void Show(CurrencyType currencyType, Action<bool> onComplete = null)
	{
		this.onComplete = onComplete;
		foreach (TabToCurrency currencyTab in currencyTabs)
		{
			if (currencyTab.currencyType == currencyType)
			{
				tabController.activeTab = currencyTab.button;
			}
			GameObject tabLayer = currencyTab.button.tabLayer;
			CurrencyPurchaseTab component = tabLayer.GetComponent<CurrencyPurchaseTab>();
			if (component != null)
			{
				component.onComplete = onComplete;
			}
		}
		NavigationManager.instance.PushModal(base.gameObject);
	}

	private void OnEnable()
	{
		if (animation != null)
		{
			animation.Play();
		}
	}

	private void CallOnComplete(bool success)
	{
		if (onComplete != null)
		{
			Action<bool> action = onComplete;
			onComplete = null;
			action(success);
		}
	}

	public override void Update()
	{
		if (IsBackPressed())
		{
			GoBack();
		}
	}

	public void GoBack()
	{
		CallOnComplete(false);
		NavigationManager.instance.Pop();
	}
}
